<?php

class VideosAdvicesAnswersController extends AppController {
    
    // TODO lejfzfj
    public $helpers = array('Html', 'Session', 'Paginator', 'Js');
    
    public $paginate = array(
        //'Comments' => array(
             'limit' => 25,        
             'order' => array(
                 'sumProsCons' => 'ASC',
                 'VideosAdvicesAnswer.posted_on DESC'
             ),
             'fields' => array(
                 'User.*', 'VideosAdvicesAnswer.*', 'VideosAdvice.users_videos_id', '(VideosAdvicesAnswer.pros - VideosAdvicesAnswer.cons) AS sumProsCons'
             ), 
             'limit' => 5,
             'recursive' => 0
        
    //)
    );
    
    
    public function getPaginatedAnswers($videoId ){
        
        $this->paginate['conditions'] = array(
            'VideosAdvice.users_videos_id' => $videoId
        );
        
        $data = $this->paginate();
        
        foreach ($data as $key => $value){
            $data[$key]['VideosAdvicesAnswer']['sum'] = $value[0]['sumProsCons'];
            unset($data[$key][0]);
        }
        $this->set('advices', $data);
    }
    
    /**
     *  Retourne la liste des conseil pour lequel l'auteur a déja voté pour une vidéo
     * @param type $videosAdvicesId 
     */
    public function getVotedAnswers($videosAdvicesId){
        return $this->VideosAdvicesAnswer->VideosAdvicesPoint->find('list', array(
            'conditions' => array(
                'VideosAdvicesPoint.videos_advices_answers_id' => $videosAdvicesId,
                'VideosAdvicesPoint.users_id' => $this->getCurrentUserId()
            )
        ));
    }
}
?>
